package com.arrogames.blondbattle.xml 
{
	import com.arrogames.blondbattle.model.FactionDefinition;
	import com.arrogames.blondbattle.model.UnitDefinition;
	import com.arrogames.blondbattle.model.WeaponDefinition;
	import com.arrogames.blondbattle.model.WorldDefinition;
	import feathers.data.ListCollection;
	/**
	 * ...
	 * @author Robin van den Bogaard
	 */
	public class WorldParser {
		
		[Embed(source = "../../../../../resources/config/worlds.xml", mimeType="application/octet-stream")]
		static private const WorldsXML:Class; 
		
		static public function parse():Array {
			var xml:XML = new XML(new WorldsXML());
			
			var retval:Array = [];
			
			for each (var worldXML:XML in xml.world) {
				var world:WorldDefinition = new WorldDefinition();
				world.name = worldXML.name;
				world.size.width = parseInt(worldXML.dimension.@width);
				
				world.humanFaction = parseFaction(worldXML.factions.human[0]);
				world.cpuFaction = parseFaction(worldXML.factions.computer[0]);
				
				retval.push(world);
			}
			
			return retval;
		}
		
		static private function parseFaction(factionXML:XML):FactionDefinition {
			var result:FactionDefinition = new FactionDefinition();
			result.baseX = parseInt(factionXML.base.@x);
			result.baseHP = parseFloat(factionXML.base.@health);
			result.spawnX = parseInt(factionXML.spawn.@x);
			result.money = parseFloat(factionXML.money.@value);
			return result;
		}
		
	}

}